<?php
class CiulanguagesController extends AppController {

	var $name = 'Ciulanguages';
        var $components = array('Session');
        var $paginate = array(
        'limit' => 12,
        'order' => array(
            'Ciulanguage.id' => 'asc'
        )
    );
	function index() {
		$this->Ciulanguage->recursive = 0;
		$this->set('ciulanguages', $this->paginate('Ciulanguage',array('Ciulanguage.id !='=>5)));// No muestra el idioma ninguno
	}
/*
	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid ciulanguage', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('ciulanguage', $this->Ciulanguage->read(null, $id));
	}
*/
	function add() {
		if (!empty($this->data)) {
			$this->Ciulanguage->create();
			if ($this->Ciulanguage->save($this->data)) {
				$this->Session->setFlash(__('The ciulanguage has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ciulanguage could not be saved. Please, try again.', true));
			}
		}
	}

/*	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid ciulanguage', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Ciulanguage->save($this->data)) {
				$this->Session->setFlash(__('The ciulanguage has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ciulanguage could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Ciulanguage->read(null, $id);
		}
	}
*/
	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for ciulanguage', true));
			$this->redirect(array('action'=>'index'));
		}
		//Cuenta cuantos cursos estan asociados a
		$rels = $this->Ciulanguage->Ciucourse->find('count', array('conditions' => array('Ciucourse.ciulanguage_id' => $id)));
		if( $rels < 1){
			if ($this->Ciulanguage->delete($id)) {
				$this->Session->setFlash(__('Ciulanguage deleted', true));
				$this->redirect(array('action'=>'index'));
			}else{
				$this->Session->setFlash(__('Ciulanguage was not deleted', true));
			}
		}else{
			$this->Session->setFlash(__('Ciulanguage was not empty', true));
		}
		$this->redirect(array('action' => 'index'));
	}
}
